package com.apesource.bookBuy.view;

import com.apesource.bookBuy.bean.PayBook;
import com.apesource.bookBuy.bean.User;
import com.apesource.bookBuy.dao.DaoUtil;
import com.apesource.bookBuy.mapper.PayBookMapper;
import com.jfinal.core.Controller;
import com.jfinal.core.Path;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * @version 1.0
 * @auther:暮雪
 * @date:2025/9/5
 */
@Path("/paybook")
public class PayBookController extends Controller {
    public void index() {
        if (getSessionAttr("users") == null) {
            redirect("/users/login");
        }
        redirect("/paybook/oldlist");
    }

    public void oldlist() {
        if (getSessionAttr("users") == null) {
            redirect("/users/login");
            return;
        }
        SqlSession sqlSession = DaoUtil.getSqlSession();
        PayBookMapper payBookMapper = sqlSession.getMapper(PayBookMapper.class);


        List<PayBook> payBookList = null;
        String bookNameKey = getPara("bookName");

        if (bookNameKey != null) {
            System.out.println(123);
            payBookList = payBookMapper.getPayBooksByUidAndBookName(((User) getSessionAttr("users")).getUid(), bookNameKey);
        } else {
            System.out.println(((User)getSessionAttr("users")).getUid());
            payBookList = payBookMapper.getPayBooksByUid(((User)getSessionAttr("users")).getUid());
            System.out.println(payBookList.toString());
        }


        DaoUtil.close(sqlSession);
        set("payBookList", payBookList);

        render("/orderlist.html", 0);

    }
}
